<?php
    class Controller extends CController
    {
        public $layout='//layouts/main';
        public $menu=array();
        public $breadcrumbs=array();

        public $pageTitle;
        public $pageDesc;
        public $pageKeywords;

        public $siteName;
        public $siteSlogan;

        public $baseUrl;
        public $socialUrl;  // url cho socila button: fb like
        public $themeUrl;
        public $themePathViews;
        public $domain;

        public $icon = array();
        public $topNav; // set active nav on top

        public $detect;
        public $useMoxie = 1;
        
        // hangve cat selected for user module
        public $catSelected = '';
        
        public function actions()
        {
            return array(
                'captcha'=> Yii::app()->params->captcha['action'],
            );
        }


        public function init(){
            // detect ie <= 8
            if(preg_match('/(?i)msie [5-8]/', $_SERVER['HTTP_USER_AGENT'])){
                $this->renderPartial('//browsers');
                Yii::app()->end();
            }
         
            // register files
            Yii::app()->clientScript->registerCoreScript('jquery');
            Yii::app()->clientScript->registerCoreScript('jquery.ui');
            Yii::app()->clientScript->registerCoreScript('cookie');
            //        Yii::app()->clientScript->registerCssFile(
            //                Yii::app()->clientScript->getCoreScriptUrl().
            //                '/jui/css/base/jquery-ui.css'
            //        );
            //Yii::app()->clientScript->registerCssFile('/files/css/jquery-ui-mac/style.css');

            // register class paths for extension captcha extended
            Yii::$classMap = array_merge( Yii::$classMap, array(
                'CaptchaExtendedAction' => Yii::getPathOfAlias('ext.captchaExtended').DIRECTORY_SEPARATOR.'CaptchaExtendedAction.php',
                'CaptchaExtendedValidator' => Yii::getPathOfAlias('ext.captchaExtended').DIRECTORY_SEPARATOR.'CaptchaExtendedValidator.php'
            ));

            //            Yii::import('ext.MobileDetect');
            //            $this->detect = new MobileDetect();

            // init properties 
            $this->pageTitle = "{$this->siteName} - {$this->siteSlogan}";

            $this->baseUrl = Yii::app()->request->getBaseUrl(TRUE);
            $this->themeUrl = Yii::app()->theme->baseUrl;
            $this->themePathViews = 'webroot.themes.'.Yii::app()->theme->name.'.views/';
            $this->domain = preg_replace('{https?://(.+)}', '$1', $this->baseUrl);

            $this->icon['ico'] = $this->baseUrl.'/files/img/favicon/favicon_16x16.ico'; 
            $this->icon['57'] = $this->baseUrl.'/files/img/favicon/apple-touch-icon-57x57.png'; 
            $this->icon['72'] = $this->baseUrl.'/files/img/favicon/apple-touch-icon-72x72.png'; 
            $this->icon['114'] = $this->baseUrl.'/files/img/favicon/apple-touch-icon-114x114.png'; 
            
        
            // under
            $password = (string)Yii::app()->request->cookies['password'];
            if($password != 'Min'){
                $this->render('//hangve/page/under');
                Yii::app()->end();    
            }
        }

        public function render($view, $data = null, $return = false, $options = null)
        {   
            $output = parent::render($view, $data, true);
            //if(!IS_LOCAL)
                $output = preg_replace('{[\n\s]+}', ' ', $output);
                
            if($return) return $output;
            else echo $output; 
        }
}